package thread;
/**
 * 静态方法如果使用synchronized修饰，那么该方法一定具有同步效果，锁的都只能是当前类
 */
public class SyncDemo2 {
    public static void main(String[] args) {
        /*Thread t1= new Thread(new Runnable() {
            @Override
            public void run() {
                Boo.doSome();
            }
        });*/
//        Thread t3 =new Thread("wkj"){
//                       public void run(){
//                   Boo.doSome();
//           }
//      };
        Thread t1 =new Thread(() ->{Boo.doSome();});
        Thread t2 =new Thread(Boo::doSome);//方法引用  run和dosome都无参就这样简写
        t1.start();
        t2.start();
    }
}

class Boo{
    /*public synchronized  static void doSome(){*/
    public static void doSome(){  //静态方法没有this
        synchronized (Boo.class) {//Boo.class为当前类对象
            try {
                Thread t = Thread.currentThread();
                System.out.println(t.getName() + "正在执行doSome方法");
                Thread.sleep(3000);
                System.out.println(t.getName() + "执行doSome方法完毕");
            } catch (InterruptedException e) {
            }
        }
    }
}
